package cn.rengy.web.framework.wxmp.message;

import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.rengy.lang.ResultEntity;
/**
 * 微信模板库
 * @author rengy
 *
 */
@Controller
@RequestMapping(value = "/authenticated/wx/msg/template")
public class WxMsgTemplateController {
	@Autowired
	private WxMsgTemplateService wxMsgTemplateService;
	
	@RequiresRoles(value={"developer"})
	@RequestMapping(value="/add",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity add (@RequestBody() Map<String,Object> paramMap) throws Exception{
		wxMsgTemplateService.add(paramMap);
		return ResultEntity.ok();
	}
	
	@RequiresRoles(value={"developer"})
	@RequestMapping(value="/update",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity update (@RequestBody() Map<String,Object> paramMap) throws Exception{
		wxMsgTemplateService.update(paramMap);
		return ResultEntity.ok();
	}
	
	@RequiresRoles(value={"developer"})
	@RequestMapping(value="/delete",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity delete (@RequestBody() Map<String,Object> paramMap) throws Exception{
		String template_id_short=MapUtils.getString(paramMap, "template_id_short");
		wxMsgTemplateService.delete(template_id_short);
		return ResultEntity.ok();
	}
}
